package com.lc.afbx.conn;

import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;
import com.zcx.helper.util.UtilLog;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/6/24.
 */
@HttpInlet(Conn.INLET_API_SHOW_VEHICLE)
public class GetApiShowVehicle extends BaseAsyGet<GetApiShowVehicle.Info> {
    public String type;

    public GetApiShowVehicle(AsyCallBack<GetApiShowVehicle.Info> asyCallBack) {
        super(asyCallBack);
    }

    protected Info parser(JSONObject jsonObject) {

        TOAST = jsonObject.optString("message");
        if (jsonObject.optInt("code") == 200) {

            Info info = new Info();
            Data d = new Data();
            JSONObject jsonObject1 = jsonObject.optJSONObject("data");

            JSONArray array1 = jsonObject1.optJSONArray("vehicletype");
            if (array1 != null) {

                for (int i = 0; i < array1.length(); i++) {

                    JSONObject o = array1.optJSONObject(i);
                    Vehicletype v = new Vehicletype();
                    v.id = o.optString("id");
                    v.title = o.optString("title");

                    d.vehicletypeList.add(v);
                }
            }

            JSONArray array2 = jsonObject1.optJSONArray("usenature");
            if (array2 != null) {
                for (int i = 0; i < array2.length(); i++) {

                    JSONObject o = array2.optJSONObject(i);
                    UseNature u = new UseNature();
                    u.id = o.optString("id");
                    u.title = o.optString("title");

                    d.useNatureList.add(u);
                }
            }
            info.data = d;
            return info;
        }

        return null;
    }

    public static class Info {
        public String message, code;
        public Data data;
    }

    public static class Data {
        public List<Vehicletype> vehicletypeList = new ArrayList<>();
        public List<UseNature> useNatureList = new ArrayList<>();
    }

    public class Vehicletype {
        public String id, title;
    }

    public class UseNature {
        public String id, title;
    }
}
